package com.ruoyi.project.cms.task.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.cms.task.domain.Assignment;
import com.ruoyi.project.cms.task.service.AssignmentService;
import com.ruoyi.project.monitor.operlog.domain.OperLog;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@Controller
@RequestMapping("/cms/task")
public class Taskcontroller extends BaseController {
    private String prefix = "cms/task";

    @Autowired
    private AssignmentService assignmentService;

    @GetMapping("/createtack")
    public String createtack()
    {
        return prefix + "/createtack";
    }

    @RequiresPermissions("monitor:operlog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Assignment assignment,String roleName)
    {
        startPage();
        List<Assignment> list = assignmentService.findMore(assignment,roleName);
        return getDataTable(list);

    }




    /**
     * 新增任务
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    @PostMapping("/addSave")
    @ResponseBody
    public AjaxResult addSave(@Validated Assignment assignment)
    {
        assignment.setNewDate(new Date());
        assignment.setAstatus(0);

        return toAjax(assignmentService.add(assignment));
    }

    /**
     * 修改
     */
    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        System.out.println(id);
        Assignment assignment = assignmentService.selectOne(id);
        System.out.println(assignment.toString());
        mmap.put("assignment", assignment);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:assignment:edit")
  //  @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/editSave")
    @ResponseBody
    public AjaxResult editSave(Assignment assignment)
    {
        return toAjax(assignmentService.updateAssignment(assignment));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:assignment:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(assignmentService.deleteAssignmentByIds(ids));
    }
}
